import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  var list=ref([])
// 未完成
var weiwancheng=computed(()=>{
  return list.value.filter((item)=>!item.status).length
})
// 新增
var xinzeng=(payload)=>{
list.value.push({id:list.value.length+1,name:payload,status:false})
}
// 改状态
var zhuangtai=(payload)=>{
  var t=list.value.find((item)=>{
    return item.id==payload
  })
  if(t){
    t.status=!t.status
  }
}
// 删除
var delrenwu=(payload)=>{
  var t=list.value.findIndex((item)=>{
    return item.id==payload
  })
  if(t!=-1){
    list.value.splice(t,1)
  }
}
  return {
    list,
    weiwancheng,
    xinzeng,
    zhuangtai,
    delrenwu,
    }
})
